package com.smartstate.dataManagement.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.smartstate.dataManagement.dto.EnergyDTO;
import com.smartstate.dataManagement.dto.common.TreeNode;
import com.smartstate.dataManagement.entity.ObjMoudel;
import com.smartstate.dataManagement.vo.EquipmentForTreeVO;
import com.smartstate.dataManagement.vo.ObjMoudelNameVo;
import com.smartstate.dataManagement.vo.ObjMoudelTwoVo;
import com.smartstate.dataManagement.vo.ObjmiddleVo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface ObjMoudelMapper extends BaseMapper<ObjMoudel> {


    /**
     * 楼宇树结构
     * @return 全部设备数据
     */
    List<EquipmentForTreeVO> selectTree();



    /**
     * 添加设备 和楼宇 中间表
     * @param objmiddleVo
     */
    int addObjmiddle(ObjmiddleVo objmiddleVo);

    /**
     * 添加图纸
     * @param
     * @return
     */
    int updatePhoto(String id ,String photo);

    /**
     * 查询全部数据返回树集合
     * @return 全部房屋数据
     */
    List<TreeNode> selectModelTree(String type);


    /**
     * 拿到楼宇id和计量管理
     * @param
     * @return
     */
    int updateMetering(String id,String metering);

    /**
     * 能源消耗分析 循环查
     * @param item
     * @return
     */
   ObjMoudelTwoVo selectMetering(EnergyDTO item);

    /**
     * 递归
     */
    List<ObjMoudelTwoVo>selectMeteringAll(String id);

    /**
     * 查图纸
     */
    ObjMoudel selectPhoto(String id);

    /**
     * 添加计量管理 查是否有这个设备
     */
    int selectDeviceIdAll(List<String> ids);

    /**
     * 查所有楼层所携带的设备 拿出楼层名 和设备deviceId
     * @return
     */
    List<ObjMoudelNameVo> getObjMoudelName();

    /**
     * 根据父id查楼层名称
     */
    ObjMoudelNameVo getName(String id);

    /**
     * 根据楼层id和类型查询
     */
    @Select("select id from objmoudel where id = #{id} and type = #{type}")
    String findIdAndType(String id, String type);

    @Select("select * from objmoudel where id = #{id} and type = #{type}")
    ObjMoudel findObjIdAndType(String id, String type);

    @Select("select * from objmoudel where id = #{id} and type = #{type}")
    ObjMoudel findNameByIdAndType(String id, String type);

    @Select("select id from objmoudel where #{id} = parentId")
    List<String> queryId(@Param("id") String id);

    @Select("select type from objmoudel where type = #{type}")
    List<String> queryType(@Param("type") String type);

    @Delete("delete from objmiddle where objId = #{id}")
    void deleteObjmiddleById(@Param("id") String id);

    @Select("select photo from objmoudel where id = #{id}")
    String queryImage(String id);

    String getObjName(String deviceId);

    @Select("select * from objmoudel where parentId = #{id}")
    List<ObjMoudel> selectByParentId(String id);

    /**
     * 获取空间结构建模下的所有objId
     * @return
     */
    @MapKey("id")
    Map<String, Object> queryAllObjId(String type);


    /**
     * 查询所有设备对应空间建模的所有objId
     * @return
     */
    @MapKey("deviceId")
    Map<String, Object>  queryAllDeviceIdFitAllObjId(String type);
}
